/*
实现弹跳小球
https://zhuanlan.zhihu.com/p/24633092

<stdlib.h>   system("cls") 实现清屏
<windows.h>  Sleep(50)  睡眠50毫秒
*/


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>


int main()
{
    int i, j;
    int x = 5, y = 10;
    int up = 0, bottom = 10;
    int left = 0, right = 20;
    int vx = 1, vy = 1;

    while(1)
    {
        x += vx;
        y += vy;
        system("cls");

        for(i=0; i < x; i++)
            printf("\n");

        for(j=0; j < y; j++)
            printf(" ");

        printf("o");
        printf("\n");
        Sleep(50);

        if(x == up || x == bottom)
            vx = -vx;
        if(y == left || y == right)
            vy = -vy;
    }

    return 0;
}
